from scaner.core.models.search_order import SearchOrder


def merge_tasks_orders(
    tasks_list: list[dict], orders_list: list[SearchOrder]
) -> list[dict]:

    order_dict = {order.id: order for order in orders_list}

    return [
        {
            "task": task_item["task"],
            "searchQuery": order_dict.get(task_item["order_id"], SearchOrder()).query_string,
            "added_at": order_dict.get(task_item["order_id"], SearchOrder()).created_at.isoformat("#", "seconds"),
        }
        for task_item in tasks_list
        if task_item["order_id"] in order_dict
    ]
